package com.openlogic.flow.controller;

import java.util.List;

import org.dromara.warm.flow.orm.entity.FlowHisTask;
import org.dromara.warm.flow.orm.entity.FlowTask;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
import org.noear.solon.core.handle.Result;
import org.noear.solon.validation.annotation.Valid;
import org.noear.solon.validation.annotation.Validated;

import com.mybatisflex.core.paginate.Page;
import com.openlogic.common.core.enums.BusinessType;
import com.openlogic.common.core.web.controller.BaseController;
import com.openlogic.common.core.web.domain.PageData;
import com.openlogic.common.core.web.validate.V_A;
import com.openlogic.common.datasource.annotation.QzLog;
import com.openlogic.flow.domain.dto.StartFlowTaskDto;
import com.openlogic.flow.domain.query.FlowTaskQuery;
import com.openlogic.flow.domain.vo.FlowHisTaskVo;
import com.openlogic.flow.domain.vo.FlowTaskVo;
import com.openlogic.flow.domain.vo.StartFlowTaskVo;
import com.openlogic.flow.service.IFlowTaskService;

/**
 * @ClassName: FlowInstanceController
 * @Description: 流程任务 控制层
 * @author weiyongpeng
 * @date 2025年2月12日 下午9:06:52
 */
@Valid
@Controller
@Mapping("flow/task")
public class FlowTaskController extends BaseController {

	@Inject
    IFlowTaskService flwTaskService;

    /**
    * 描述：启动任务
    * @Title: startWorkFlow
    * @param startFlowTaskDto 流程启动
    * @return
    * @author weiyongpeng
    * @date  2025年2月13日 下午1:45:56
     */
    @QzLog(title = "任务管理", businessType = BusinessType.INSERT)
    @Post
    @Mapping("startWorkFlow")
    public Result<StartFlowTaskVo> startWorkFlow(@Validated(V_A.class) @Body StartFlowTaskDto startFlowTaskDto) {
    	StartFlowTaskVo startProcessReturn = flwTaskService.startWorkFlow(startFlowTaskDto);
        return Result.succeed(startProcessReturn, "提交成功");
    }
    
    /**
    * 描述：分页查询待办列表
    * @Title: undoList
    * @param page
    * @param flowDefinitionQuery
    * @return
    * @author weiyongpeng
    * @date  2025年2月18日 下午8:21:10
     */
    @QzLog(title = "流程代办任务列表", businessType = BusinessType.LIST)
	@Get
	@Mapping("/undo/list")
    public PageData<FlowTaskVo> undoList(Page<FlowTask> page, FlowTaskQuery flowTask) {
    	startPage(page);
		List<FlowTaskVo> listPage = flwTaskService.listUndoByPage(flowTask);
		return getPageData(listPage);
    }
    
    /**
     * 描述：分页查询已办列表
     * @Title: undoList
     * @param page
     * @param flowDefinitionQuery
     * @return
     * @author weiyongpeng
     * @date  2025年2月18日 下午8:21:10
      */
    @QzLog(title = "流程已办任务列表", businessType = BusinessType.LIST)
 	@Get
 	@Mapping("/done/list")
     public PageData<FlowHisTaskVo> doneList(Page<FlowHisTask> page, FlowTaskQuery flowTask) {
     	startPage(page);
 		List<FlowHisTaskVo> listPage = flwTaskService.listhasDoneByPage(flowTask);
 		return getPageData(listPage);
     }
	
}
